package com.wc.AlgoOJ_homework.AlgoOJ_BL1.D_第八大奇迹;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/3/30 13:48
 * @description http://43.138.190.70:8888/p/163?tid=65f926e1f748afd09501f854
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010;
    static int M = 10;
    static int[][] f = new int[N << 2][M];
    static int n, q;
    static int a, b;

    public static void main(String[] args) {
        n = sc.nextInt();
        q = sc.nextInt();
        while (q-- > 0) {
            String op = sc.next();
            a = sc.nextInt();
            b = sc.nextInt();
            if (op.equals("C")) {
                add(1, n, 1, a, b);
            } else {
                out.println(query(1, n, 1, a, b)[8]);
            }
        }
        out.flush();
    }

    static int[] query(int l, int r, int t, int ql, int qr) {
        if (l == ql && r == qr) {
            return f[t];
        }
        int mid = l + r >> 1;
        if (mid >= qr) return query(l, mid, t << 1, ql, qr);
        else if (mid + 1 <= ql) return query(mid + 1, r, t << 1 | 1, ql, qr);
        int[] a = query(l, mid, t << 1, ql, mid);
        int[] b = query(mid + 1, r, t << 1 | 1, mid + 1, qr);
        return combine(a, b);
    }

    static void add(int l, int r, int t, int x, int v) {
        if (l == r) {
            f[t][1] = v;
            f[t][0] = 1;
            return;
        }
        int mid = l + r >> 1;
        if (x <= mid) add(l, mid, t << 1, x, v);
        else add(mid + 1, r, t << 1 | 1, x, v);
        f[t] = combine(f[t << 1], f[t << 1 | 1]);
    }

    static int[] combine(int[] a, int[] b) {
        int[] c = new int[M];
        int i = 1, j = 1, k = 1;
        while (i <= a[0] && j <= b[0] && k <= 8) {
            if (a[i] > b[j]) c[k++] = a[i++];
            else c[k++] = b[j++];
        }
        while (i <= a[0] && k <= 8) c[k++] = a[i++];
        while (j <= b[0] && k <= 8) c[k++] = b[j++];
        c[0] = --k;
        return c;
    }

    static void build(int l, int r, int t) {
        if (l == r) {
            f[t][0] = 1;
            return;
        }
        int mid = l + r >> 1;
        build(l, mid, t << 1);
        build(mid + 1, r, t << 1 | 1);
        f[t] = combine(f[t << 1], f[t << 1 | 1]);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
